package com.xxp.controller;


import com.xxp.common.Result;
import com.xxp.controller.request.HistoryRequest;
import com.xxp.entity.History;
import com.xxp.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/history")
public class HistoryController {
    @Autowired
    private HistoryService historyService;

    @GetMapping("/find")
    public Result selectById() {
        return Result.success(historyService.selectByFzId(2));
    }
    @GetMapping("/name")
    public Result selectName(){
        return Result.success(historyService.selectName());
    }
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id){
        History history = historyService.selectByID(id);
        historyService.updateViews(history);
        return Result.success(history);
    }

    @GetMapping("/page")
    public Result findAll( HistoryRequest historyRequest){
        return Result.success(historyService.findAll(historyRequest));
    }

    @PutMapping("/update")
    public Result updateHistory(@RequestBody History history){
        historyService.updateHistory(history);
        return Result.success();
    }
}
